package go_bloom_filter

import "sync"

// the length of []byte array that used to keep hash code
var ByteArrLength int = 0x8000000
var Seed = [10]int{3, 7, 11, 13, 17, 23, 31, 33, 37, 133}

type bloomFiler struct {
	bitMap []byte     //存储hash值
	count  uint32     //计数器
	bb     sync.Mutex //互斥锁
}

func GetFilter() *bloomFiler {
	var bf *bloomFiler = &bloomFiler{bitMap: make([]byte, ByteArrLength), count: 0, bb: sync.Mutex{}}
	return bf
}

// add member to filter
func (bf *bloomFiler) Add(member string) error {
	bf.bb.Lock()
	defer bf.bb.Unlock()
	var hashCode uint
	seedNum := len(Seed)
	for i := 0; i < seedNum; i++ {
		hashCode = getHashCode(member, Seed[i])
	}
	bf.count++
	return nil
}

// dose exist in filter
func (bf *bloomFiler) Contains(needle interface{}) bool {
	return false
}

// calculate hash code
func getHashCode(str string, seed int) uint {
	var result uint = 0

	return result
}
